define(['api'], function (api) {
  'use strict';

  var HouseList = {
    name: 'house-list',
    template: '' +
    '<div style="height: 100%;">'+
    '        <div class="list_right_top">'+
    '            <div class="textlisttop">'+
    '                <div class="address_img"></div>'+
    '                <strong>{{ locationText }}</strong>'+
    '                <span>{{ dataList.length }}套</span>'+
    '                <div class="defaultsort_box">'+
    '                    <i-Select placeholder="默认排序">'+
    '                    </i-Select>'+
    '                </div>'+
    '            </div>'+
    '            <div class="average_price">'+
    '                <span>12341.23元/㎡</span>'+
    '            </div>'+
    '        </div>'+
    '        <div class="list_right_down">'+
    '            <h3 class="jiantou"></h3>'+
    '            <div class="listrightdownbox" v-for="item in dataList">'+
    '                <div class="imagetext01">'+
    '                    <div class="imgtext-box">'+
    '                        <div class="roomimg"></div>'+
    '                        <div class="roomtextimg">'+
    '                            <div class="roomtext">{{ item.name }}</div>'+
    '                            <div class="roomlocation_img"></div>'+
    '                        </div>'+
    '                        <div class="address">'+
    '                            <span>{{ item.address }}</span>'+
    '                        </div>'+
    '                        <div class="moneydonw">'+
    '                            <p>{{ item.hallNumber }}室{{ item.roomNumber }}厅 {{ item.squareMeters }}㎡</p>'+
    '                            <span>{{ item.totalPrice | million }}</span>'+
    '                        </div>'+
    '                    </div>'+
    '                </div>'+
    '            </div>'+
    '        </div>'+
    '    </div>',

    props: {

    },

    data: function () {
      return {
        dataList: [],
        queryParams: {
          plotId: '',
          district: '',
          city: '',
          type: '',
          price: '',
          houseType: '',
          area: '',
          more: ''
        }
      }
    },

    watch: {
      queryParams: {
        deep: true,
        handler: function (data) {
          var that = this;
          api.fetchMapHouseList(data)
              .done(function (res) {
                if (res.IsSuccess) {
                  that.dataList = res.ResultObject;
                }
              });
        }
      }
    },

    computed: {
      locationText: function () {
        return this.queryParams.district !== '' ? this.queryParams.district : this.queryParams.city;
      }
    },

    filters: {
      million: function (val) {
        return (val * 0.0001).toFixed(2) + '万';
      }
    },

    methods: {
    },

    created: function () {
      var that = this;
      window.bus.$on('map-move', function (data) {
        that.queryParams.city = data.city;
        that.queryParams.district = data.district;
      });

      window.bus.$on('update-query-params', function (data) {
        that.queryParams = data;
      });

      window.bus.$on('update-plot-id', function (id) {
        that.queryParams.plotId = id;
      });
    }
  };

  return HouseList;
});
